
// 代理目标
const proxyTarget = {
    id: 1 ,
    name: '张阿姨' ,
    gender: 'female' ,
    eat(food){
        console.log( this.name , '吃' , food );
    }
}

const handler = {
    get(target,field){
        console.log( `获取 ${field}` );
        return target[ field ];
    },
    set(target,field,value) {
        console.log( `为 ${field} 赋值 ${value}` );
        target[ field ] = value ;
    }
}

// 代理对象
const proxyObject = new Proxy( proxyTarget , handler );
console.log( proxyObject.id , proxyObject.name , proxyObject.gender );

proxyObject.id = 1001 ;
proxyObject.name = '朱亚红' ;
proxyObject.gender = '女' ;

console.log( proxyTarget.id , proxyTarget.name , proxyTarget.gender );